<html>
<head>
<script>
if (window.testRunner) {
    testRunner.dumpAsText();
    testRunner.setDumpConsoleMessages(false);
    testRunner.waitUntilDone();
    testRunner.setPopupBlockingEnabled(false);
}

function log(msg) {
    var div = document.createElement("div");
    div.appendChild(document.createTextNode(msg));
    document.getElementById("console").appendChild(div);
}

var readyCount = 0;
window.addEventListener("message", function(e) {
    if (e.data == "ready") {
        ++readyCount;
        if (readyCount == 2) {
            helper.postMessage("set", "*");
        }
    } else if (e.data == "pass") {
        target.document.body.innerHTML = "Should have navigated this window.  It should still be same-origin.";
        log("PASS");
        // We expect the following windows to be counted here:
        // 1. The main test window (this window).
        // 2. The |target| window, which is same site.
        // 3. The |helper| window opened |win| within this site.
        // In site-per-process, the |helper| window itself is cross-site so not counted.
        // In not-site-per-process, all windows share the same renderer, so:
        // 4. The |helper| cross-site window.
        log("There are currently " + testRunner.windowCount() + " windows opened.");
        target.close();
        helper.postMessage("cleanup", "*");
    } else if (e.data == "done") {
        helper.close();
        if (window.testRunner)
            testRunner.notifyDone();
    }
}, false);

window.onload = function() {
    target = window.open("resources/ready.html", "targetWindow");
    helper = window.open("http://localhost:8000/security/frameNavigation/resources/not-opener-helper.html");
}
</script>
</head>
<body>
<div id="console"></div>
</body>
</html>

